<?php
class Con_proxy extends Acan{
	public $defaultAct='open';
	function __construct($ainfo=null){
		parent::__construct($ainfo=null);
	}
	function Act_open(){
		global $_G;
		$site = $_GET['url'];
		if(empty($site)){$site = 'www.baidu.com';}
		$siteurl = Afun_urldecode($site);
		if($siteurl){
			$url=$siteurl;
			if(function_exists('curl_init')){
				$curl = curl_init();
				curl_setopt($curl, CURLOPT_URL, $url);
				//curl_setopt($curl, CURLOPT_HTTPHEADER, array ("user_agent" => "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.6) Gecko/20091201 Firefox/3.5.6 (.NET CLR 3.5.30729)","language" => "en-us,en;q=0.5"));
				curl_setopt($curl, CURLOPT_RETURNTRANSFER,1);
				curl_setopt($curl, CURLOPT_ENCODING, "gzip,deflate");
				if($_POST){
					curl_setopt($curl, CURLOPT_POST, 1);
					curl_setopt($curl, CURLOPT_POSTFIELDS, $this->postdata());
				}
				$file_contents = curl_exec($curl);
				curl_setopt($curl, CURLOPT_HEADER, 1);
				curl_setopt($curl, CURLOPT_NOBODY, 1);
				$data=curl_exec($curl);
				$source = explode("\r\n",$data);
				//显示curl获得的header信息
				curl_close($curl);
			}
			foreach ($source as $k=>$v){
				if(preg_match("/Content-Type.*/",$v)){header($v);}
				if(preg_match("/Content-Encoding.*/",$v)){header($v);}
				if(preg_match("/Set-Cookie.*/",$v)){header($v);}
				if(preg_match("/Transfer-Encoding.*/",$v)){header($v);}
				//if(preg_match("/Content-Length.*/",$v)){continue;}
			}
			header("Content-Length: ".strlen($file_contents));
			echo $file_contents;
		}
	}
	function Act_kuaidi(){
		header('Content-type: text/html; charset=UTF-8');
		header('Access-Control-Allow-Origin: *');
	/*	$body = file_get_contents('./kd.log');
		echo strlen($body);
		preg_match('/(<table.*?>.+?<\/table>)/',$body,$table);
		print_r($table);
		return;*/
		$city = $_GET['city'];
		$city = '宁波';
		$search_url = "http://jingang.yto56.com.cn/ord/ordquery/searchOrdersByPage.action?mainAction=mainOrderList_searchOrdersByPage&orderChannelCode=&pageSize=100&pageIndex=0&conditionOption=senderCityName&conditionText=&orderTypeCode=&assignOrgCode=&logistics=&timeout=&include=&orgCode=&orgName=&sortName=&sortType=&isProcess=&senderProvName=&startDate=&endDate=&rand=";
		$url = str_replace('conditionText=','conditionText='.$city,$search_url);
		$cookie_yto = "BIGipServerPool_common=2042691850.36895.0000; BIGipServerPool_expquery=2462777610.30755.0000; BIGipServerPool_mat=1136787722.32035.0000; BIGipServerPool_mdm=1153564938.30755.0000; BIGipServerPool_ord=1388445962.30755.0000; BIGipServerPool_stl=1153564938.31523.0000; JSESSIONID=0000zgxV4aGoZNKC70uyfXXRy01:17qp82fjk; TOKEN=8a8142c43e4fa032013e5fbb4e730596|PqTflP07Jie2hSI_aWkoKdc|exp;";
		$fp = fsockopen("jingang.yto56.com.cn",80,$errno,$errstr,30) or exit($errstr."--->".$errno);
		$header = array (
			"GET ".str_replace("http://jingang.yto56.com.cn",'',$url)." HTTP/1.1",
			"user_agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.6) Gecko/20091201 Firefox/3.5.6 (.NET CLR 3.5.30729)",
			"Accept: */*",
		//	"Accept-Encoding: gzip, deflate",
			"Accept-Language: zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3",
			"Cache-Control: no-cache",
			"Host: jingang.yto56.com.cn",
		//	"Referer"=>"http://jingang.yto56.com.cn/",
			"Cookie: ".$cookie_yto,
			"Connection: Close",
		);
		if (!$fp) {
			echo "$errstr ($errno)<br />\n";
		}else{
			fputs($fp,implode("\r\n",$header)."\r\n"."\r\n");
			$inheader = 1;
			while (!feof($fp)) {  
				$line = fgets($fp,1024); //去除请求包的头只显示页面的返回数据
				//echo $line;
				if ($inheader && ($line == "\n" || $line == "\r\n")) {$inheader = 0;}
				if ($inheader == 0) {$body .= $line;}
			}
			fclose($fp);
		}
		echo $body;
		/*
	var trr=html.match(/(<table[^]*?>[^]+?<\/table>)/)[0].match(/<tr([^]+?)<\/tr>/g);
	var obj = {};
	var otype = ['send','order','recv','status'];
	for (var i in trr) {
		var orr = trr[i].match(/(orderid|orderId)="([\w\d]+)"/);
		if(orr && orr[2]){
			var orderid = orr[2];
			if(!obj[orderid]) obj[orderid]={};
			var tdr = trr[i].replace(/(\t|\r)/g,'').match(/<ul>[^]*?<\/ul>/g);
			for(var x in tdr){
				if(!obj[orderid][otype[x]]) obj[orderid][otype[x]] = {};
				var ulr = tdr[x].replace(/<[^]*?>/g,'').split("\n");
				for(var l in ulr){
					if(ulr[l]=='') continue;
					var lrr = ulr[l].split('：');
					if(lrr.length>1){
						obj[orderid][otype[x]][trim(lrr[0])]=trim(lrr[1]);
					}
				}
			}
		}
	};
	return obj;
	*/
	}
	function postdata($pkey=array(),$obj=''){
		if(empty($obj)){$obj = $_POST;}
		foreach ($obj as $key => $val) {
			if(is_array($val) || is_object($val)){
				$pkeys = $pkey;
				$pkeys[] = $key;
				$str .= $this->postdata($pkeys,$val);
				unset($pkey);
			}else{
				if(is_array($pkey) && !empty($pkey)){
					foreach ($pkey as $k => $v) {
						if(empty($pstr)){
							$pstr = $v;
						}else{
							$pstr .= "[$v]";
						}
					}
					$pstr .= "[$key]";
				}else{
					$pstr = $key;
				}
				$val = urlencode($val);
				$str .= "$pstr=$val&";
				unset($pstr);
			}
		}
		return $str;
	}
}
?>